<template>
  <div class="app-container">
    <el-card>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-input
            v-model="keyWord"
            placeholder="请输入想要查询的信息"
            @keyup.enter.native.prevent="searchSCByName"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="searchSCByName"
            >搜索</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="dialogAddVisible = true"
            icon="el-icon-plus"
            >添加</el-button
          >
          <el-dialog title="新增一个课程信息" :visible.sync="dialogAddVisible">
            <el-form @submit.native.prevent :model="scInfo">
              <el-form-item label="学生名称">
                <el-input v-model="scInfo.sId"></el-input>
              </el-form-item>
              <el-form-item label="课程名称">
                <el-input v-model="scInfo.cId"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogAddVisible = false">取 消</el-button>
              <el-button type="primary" @click="addSCSubmit">确 定</el-button>
            </div>
          </el-dialog>
        </el-form-item>
      </el-form>

      <!--SC table-->
      <el-table
        v-loading="listLoading"
        :data="list"
        element-loading-text="Loading"
        stripe
        height="550"
        border
        fits
        highlight-current-row
      >
        <el-table-column align="center" label="学号" prop="sId" />
        <el-table-column label="学生名称" align="center" prop="sName" />
        <el-table-column label="性别" align="center" prop="sSex" />
        <el-table-column label="年龄" align="center" prop="sAge" />
        <el-table-column label="课程编号" align="center" prop="cId" />
        <el-table-column label="课程名称" align="center" width="150" prop="cName" />
        <el-table-column label="学院编号" align="center" prop="deptId" />
        <el-table-column label="学院名" align="center" width="180" prop="deptName" />
        <el-table-column label="学院地址" align="center" prop="address" />
        <el-table-column label="分数" align="center" prop="score" />
        <el-table-column label="操作" align="center">
          <template slot-scope="{ row }">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              circle
              style="margin-left: 0"
              v-show="!row.isEdit"
              @click="row.isEdit = !row.isEdit"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-check"
              circle
              style="margin-left: 0"
              v-show="row.isEdit"
              size="small"
              @click="editOneSCInfo(row)"
            ></el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="small"
              circle
              @click="deleteOneSCInfo(row.cId)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getAllSCInfo } from "@/api/course";
export default {
  data() {
    return {
      list: null,
      listLoading: true,
      keyWord: "",
      dialogAddVisible: false,
      scInfo: {
        sId: "",
        cId: "",
      },
    };
  },
  methods: {
    fetchData() {
      this.listLoading = true;
      getAllSCInfo().then((response) => {
        this.list = response.data.map((v) => {
          this.$set(v, "isEdit", false);
          return v;
        });
        this.list = response.data;
        this.listLoading = false;
      });
    },

    addSCSubmit() {},
    searchSCByName() {},
    editOneSCInfo(row) {
      row.isEdit = false;
    },
    deleteOneSCInfo() {},
  },
  created() {
    this.fetchData();
  },
};
</script>
